package com.example.hospitalmanagementapp

import Fragment.NewBornFragment
import Fragment.PeopleChildFragment
import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.FrameLayout
import android.widget.RadioGroup
import androidx.fragment.app.Fragment
import kotlinx.android.synthetic.main.activity_increase.*

class IncreaseActivity: AppCompatActivity(),RadioGroup.OnCheckedChangeListener{
    private  val datatList= arrayListOf(PeopleChildFragment(this),NewBornFragment(this))


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_increase)
        initView()
    }

    private fun initView() {
        val radioGroup:RadioGroup=findViewById(R.id.radio_group)
        radioGroup.setOnCheckedChangeListener(this)
    // var frameLayout:FrameLayout=findViewById(R.id.people_layout)
        var ft=supportFragmentManager.beginTransaction()
        datatList.forEach {
            ft.add(R.id.people_layout,it)
                .hide(it)}
        ft.show(datatList[0])
        ft.commit()
    }

    override fun onCheckedChanged(group: RadioGroup?, checkedId: Int) {
                if (checkedId==R.id.people_child){
                    var ft=supportFragmentManager.beginTransaction()
                    datatList.forEach {
                        ft.hide(it)
                    }
                    ft.show(datatList[0])
                    ft.commit()
                }
                if (checkedId==R.id.new_born){
                    var ft=supportFragmentManager.beginTransaction()
                    datatList.forEach {
                        ft.hide(it)
                    }
                    ft.show(datatList[1])
                    ft.commit()
                }
            }


}

